package com.swagger.swaggerdemo.controller;

import com.swagger.swaggerdemo.bean.User;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * @Api 描述的是Controller：tag:标签，版本号，value:字段说明，description:注释说明这个类。
 */
@RestController
@RequestMapping(value = "/users")
@Api(tags = "1.0", value = "用户管理", description = "用户管理")
public class UserController {
    private final static Logger log = LoggerFactory.getLogger(UserController.class);

    @GetMapping("/query")
    @ApiOperation(value = "查询操作（query）")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户名", name = "username"),
            @ApiImplicitParam(value = "密码", name = "password")
    })
    @ApiResponses({
            @ApiResponse(code = 202, message = "返回user")
    })
    public User query(String username, String password) {
        log.info("多个参数用  @ApiImplicitParams");
        return new User(1L, username, password);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "主键查询（done）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户编号")
    })
    public User get(@PathVariable Long id) {
        log.info("单个参数用  @ApiImplicitParam");
        return new User(id, "u1", "p1");
    }

    @PostMapping
    @ApiOperation(value = "添加用户（done）")
    public User post(@RequestBody User user) {
        log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @ApiImplicitParam");
        return user;
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "修改用户（done）")
    public void put(@PathVariable Long id, @RequestBody User user) {
        log.info("如果你不想写 @ApiImplicitParam 那么 swagger 也会使用默认的参数名作为描述信息 ");
    }

    @GetMapping("/info")
    public String getInfo(){
        return "Ok";
    }
    @GetMapping("/info2")
    public String getInfo2(){
        return "Ok";
    }
}
